package view
{
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;

    import view.ImageLocator;

    public class People extends Sprite
    {
        public static var POINT_NUM:int = 128;

        public var people:Bitmap = new ImageLocator.people();
        public var mouseLine:Array = new Array();
        public var lineLength:int;
        public var speed:int;

        public function People()
        {
            this.people.x = 0;
            this.people.y = 200;
            this.speed = 2;
            this.lineLength = People.POINT_NUM;
            for(var i:int=0; i<this.lineLength; i++)
            {
                this.mouseLine.push([2*i, 200]);
            }
            this.addChild(this.people);
        }

        public function display():void
        {
            this.graphics.clear();
            this.graphics.moveTo(0, this.mouseLine[0][0]);
            for(var i:int=0; i<People.POINT_NUM; i++)
            {
                var v:int = Math.random() * 2;
                if((v&1) == 0) this.graphics.lineStyle(6, 0x00FF00, 0.8, false, "normal", "round", "round");
                else this.graphics.lineStyle(6, 0xFFFF00, 0.8, false, "normal", "round", "round");
                this.graphics.lineTo(this.mouseLine[i][0], this.mouseLine[i][1]);
            }
        }

        public function move(speed:int):void
        {
            this.speed = speed;
            this.lineLength = People.POINT_NUM - 2*People.POINT_NUM/speed;
            for(var i:int=1; i<this.mouseLine.length; i++)
            {
                this.mouseLine[i][0] -= speed;
                if(this.mouseLine[i-1][0] <= this.people.width &&
                   this.people.width <= this.mouseLine[i][0])
                {
                    this.people.y = this.mouseLine[i][1] - this.people.height;
                }
            }
            this.mouseLine.shift();
            if(this.mouseY >= this.people.height &&
               this.mouseY <= 420)
            {
                
                this.mouseLine.push([256, this.mouseY]);
            }
            else
            {
                if(this.mouseY < this.people.height)
                {
                    this.mouseLine.push([256, this.people.height]);
                }
                else
                {
                    this.mouseLine.push([256, 420]);
                }
            }
        }
    }
}
